package com.uneed.widget;

import com.uneed.R;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView.Tokenizer;

public class AutoCompleteTextView extends MultiAutoCompleteTextView
{
  public static String[] suggests;

  static
  {
    String[] arrayOfString = new String[8];
    arrayOfString[0] = "@163.com";
    arrayOfString[1] = "@qq.com";
    arrayOfString[2] = "@126.com";
    arrayOfString[3] = "@gmail.com";
    arrayOfString[4] = "@sina.com";
    arrayOfString[5] = "@sohu.com";
    arrayOfString[6] = "@hotmail.com";
    arrayOfString[7] = "@yahoo.cn";
    suggests = arrayOfString;
  }

  public AutoCompleteTextView(Context paramContext)
  {
    super(paramContext);
    init(paramContext);
  }

  public AutoCompleteTextView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    init(paramContext);
  }

  public AutoCompleteTextView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    init(paramContext);
  }

  public void init(Context paramContext)
  {
    setAdapter(new ArrayAdapter(paramContext, R.layout.auto_com_text_item, suggests));
    setThreshold(0);
//    setDropDownVerticalOffset(DPUtils.dip2px(paramContext, 4.0F));
    setTokenizer(new AtTokenizer());
  }

  class AtTokenizer
    implements MultiAutoCompleteTextView.Tokenizer
  {
    AtTokenizer()
    {
    }

    public int findTokenEnd(CharSequence paramCharSequence, int paramInt)
    {
      return paramCharSequence.length();
    }

    public int findTokenStart(CharSequence paramCharSequence, int paramInt)
    {
      for (int i = paramInt; ; --i)
      {
        if ((i > 0) && (paramCharSequence.charAt(i + -1) != '@'))
          continue;
        if ((i > 0) && (paramCharSequence.charAt(i + -1) == '@'))
          --i;
        return i;
      }
    }

    public CharSequence terminateToken(CharSequence paramCharSequence)
    {
      return paramCharSequence;
    }
  }
}